home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / hlp_auth / clak20 / generapp.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-01-10  |  16.2 KB  |  422 lines

  1. VERSION 2.00
  2. Begin Form Clacker_Form 
  3.    Caption         =   "Clacker Test"
  4.    ClientHeight    =   5580
  5.    ClientLeft      =   1185
  6.    ClientTop       =   1785
  7.    ClientWidth     =   5070
  8.    Height          =   6270
  9.    Left            =   1125
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5580
  12.    ScaleWidth      =   5070
  13.    Top             =   1155
  14.    Width           =   5190
  15.    Begin CommandButton BTN_Command1 
  16.       Caption         =   "On/Off"
  17.       Height          =   375
  18.       Left            =   120
  19.       TabIndex        =   6
  20.       Top             =   240
  21.       Width           =   855
  22.    End
  23.    Begin Clack Clacker1 
  24.       Prop10          =   "Click for About Box"
  25.       hwndForm        =   0
  26.       Left            =   240
  27.       SystemMenu      =   0   'False
  28.       Top             =   120
  29.    End
  30.    Begin CommandButton BTN_Exit 
  31.       Caption         =   "Exit"
  32.       Height          =   375
  33.       Left            =   3720
  34.       TabIndex        =   4
  35.       Top             =   240
  36.       Width           =   1215
  37.    End
  38.    Begin TextBox Text2 
  39.       Height          =   2655
  40.       Left            =   120
  41.       MultiLine       =   -1  'True
  42.       ScrollBars      =   3  'Both
  43.       TabIndex        =   3
  44.       Text            =   "Text2"
  45.       Top             =   840
  46.       Width           =   4815
  47.    End
  48.    Begin CommandButton Btn_UnHook 
  49.       Caption         =   "UnHook"
  50.       Height          =   375
  51.       Left            =   1080
  52.       TabIndex        =   1
  53.       Top             =   240
  54.       Width           =   1215
  55.    End
  56.    Begin CommandButton Btn_Hook 
  57.       Caption         =   "Hook"
  58.       Height          =   375
  59.       Left            =   2400
  60.       TabIndex        =   2
  61.       Top             =   240
  62.       Width           =   1215
  63.    End
  64.    Begin TextBox TXT_Result 
  65.       Height          =   975
  66.       Left            =   120
  67.       MultiLine       =   -1  'True
  68.       TabIndex        =   0
  69.       Text            =   "Menu ID, menu not hooked"
  70.       Top             =   3720
  71.       Width           =   4815
  72.    End
  73.    Begin Label Label1 
  74.       BackColor       =   &H00FFFF80&
  75.       Caption         =   "Label1"
  76.       Height          =   375
  77.       Left            =   120
  78.       TabIndex        =   5
  79.       Top             =   4920
  80.       Width           =   4815
  81.    End
  82.    Begin Menu nmu_File 
  83.       Caption         =   "&File"
  84.       HelpContextID   =   9
  85.       Tag             =   "mnu_File tag text"
  86.       Begin Menu mnu_New 
  87.          Caption         =   "New"
  88.          Tag             =   "mnu_New tag text"
  89.       End
  90.       Begin Menu mnu_Open 
  91.          Caption         =   "Open"
  92.          Tag             =   "mnu_Open tag text"
  93.       End
  94.       Begin Menu mnu_Close 
  95.          Caption         =   "Close"
  96.          Tag             =   "mnu_Close tag text"
  97.       End
  98.       Begin Menu mnu_Exit 
  99.          Caption         =   "&Exit"
  100.          HelpContextID   =   1
  101.          Tag             =   "mnu_Exit tag text"
  102.       End
  103.    End
  104.    Begin Menu mnu_Edit 
  105.       Caption         =   "&Edit"
  106.       HelpContextID   =   2
  107.       Tag             =   "mnu_Edit tag text"
  108.       Begin Menu mnu_Cut 
  109.          Caption         =   "Cu&t"
  110.          HelpContextID   =   3
  111.          Shortcut        =   ^X
  112.          Tag             =   "mnu_Cut tag text"
  113.       End
  114.       Begin Menu mnu_Copy 
  115.          Caption         =   "&Copy"
  116.          HelpContextID   =   4
  117.          Shortcut        =   ^C
  118.          Tag             =   "mnu_Copy tag text"
  119.       End
  120.       Begin Menu mnu_Paste 
  121.          Caption         =   "&Paste"
  122.          HelpContextID   =   5
  123.          Shortcut        =   ^V
  124.          Tag             =   "mnu_Paste tag text"
  125.       End
  126.       Begin Menu mnu_EditSubmenu 
  127.          Caption         =   "Edit SubMenu"
  128.          HelpContextID   =   6
  129.          Tag             =   "mnu_EditSubmenu tag text"
  130.          Begin Menu mnu_EditSubmenu1 
  131.             Caption         =   "Edit SubMenu 1"
  132.             HelpContextID   =   7
  133.             Tag             =   "mnu_EditSubmenu1 tag text"
  134.          End
  135.          Begin Menu mnu_EditSubmenu2 
  136.             Caption         =   "Edit SubMenu 2"
  137.             HelpContextID   =   8
  138.             Tag             =   "mnu_EditSubmenu2 tag text"
  139.          End
  140.       End
  141.    End
  142.    Begin Menu mnu_View 
  143.       Caption         =   "&View"
  144.       Tag             =   "mnu_View tag text"
  145.       Begin Menu mnu_View1 
  146.          Caption         =   "View 1"
  147.          Tag             =   "mnu_View1 tag text"
  148.       End
  149.       Begin Menu mnu_View2 
  150.          Caption         =   "View 2"
  151.          Tag             =   "mnu_View2 tag text"
  152.       End
  153.       Begin Menu mnu_ViewSubMenu 
  154.          Caption         =   "View SubMenu"
  155.          Tag             =   "mnu_ViewSubMenu tag text"
  156.          Begin Menu mnu_ViewSubMenu1 
  157.             Caption         =   "View SubMenu 1"
  158.             Tag             =   "mnu_ViewSubMenu1 tag text"
  159.          End
  160.          Begin Menu mnu_ViewSubMenu2 
  161.             Caption         =   "View SubMenu 2"
  162.             Tag             =   "mnu_ViewSubMenu2 tag text"
  163.          End
  164.       End
  165.    End
  166. Option Explicit
  167. Const CLACKER_START = 1
  168. Const CLACKER_STOP = 2
  169. Dim CRLF As String
  170. Dim MenuStatus(1 To 25) As HelpTextType  '' help string array
  171. Dim LocalMenuIDArray() As Long           '' local menu ID array
  172. Sub BTN_Command1_Click ()
  173. ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  174. '' COMMENT: Switches a menu item on and off...just to show how
  175. ''''''''''''''''''''''''''''''''''''''''''''''''''''''
  176.     If mnu_Copy.Visible Then
  177.         mnu_Copy.Visible = False
  178.         BTN_Command1.Caption = "OFF"
  179.     Else
  180.         mnu_Copy.Visible = True
  181.         BTN_Command1.Caption = "ON"
  182.     End If
  183.     '' fill the local array
  184.     Clacker1.RefreshHwnd = Me.hWnd
  185. End Sub
  186. Sub BTN_Exit_Click ()
  187.     '' user initiated exit
  188.     mnu_Exit_Click
  189. End Sub
  190. Sub Btn_Hook_Click ()
  191. '' PURPOSE: Hook up the menu to CLACKER.VBX
  192. '' COMMENTS: Each form with a menu to monitor
  193. ''           should have a similar statement block
  194. '''''''''''''''''''''''''''''''''''''''''''''''''''
  195.     '' set the HWND of this form
  196.     Clacker1.hwndForm = Me.hWnd
  197.     Debug.Print Hex$(Me.hWnd)
  198.     '' issue the action command
  199.     Clacker1.Action = CLACKER_START   ''1
  200.     '' put up some status info
  201.     TXT_Result.Text = "Menu ID, menu hooked"
  202. End Sub
  203. Sub Btn_UnHook_Click ()
  204.     '' user initiated unhook command
  205.     '' unhook the menu
  206.     Clacker1.Action = CLACKER_STOP  ''2
  207.     '' some status text
  208.     TXT_Result.Text = "Menu Unhooked"
  209.     Label1.Caption = ""
  210. End Sub
  211. Sub Clacker1_ClackerClick (MenuName As String, TagText As String, MenuCaption As String, MenuID As Integer, hMenu As Integer)
  212. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  213. ' PURPOSE: Determine which menu was hit.
  214. ' COMMENTS: Clacker.vbx returns all the values shown from windows.
  215. '           Read the SDK docs, to better understand Window's menu behavior.
  216. '           Parametrs returned are:
  217. '               hMenu the menu handle
  218. '               MenuID the resource ID of the menu ( actually a Unsigned Integer )
  219. '               MenuCaption the menu caption text
  220. ' NOTES:    1. It is not necessary to make use of all of the return params.
  221. '               Using only the MenuID is suffecient to retreive the stored text.
  222. '           2. Clacker does not return a caption for all menu hits. Windows does
  223. '               not provide return captions for typically unused menu items,
  224. '               ie, separators and those menu items which are processed by
  225. '               Window's default menuprocs.
  226. '           3. Separators return MenuID = 0 for all of them.
  227. '           4. Top level menus and submenus return hMenu = MenuID.
  228. '           5. How to get to the status text...
  229. '               Make a text array with the text strings you want to use for each menu item
  230. '               Use the ndex value as a position of the match to fetch the text string.
  231. '           6. Break Points in this Sub suspends execution in a menu call so the VB menus
  232. '               will be disabled until the Sub exits. Use Debug.Print statements instead
  233. '               of break points to debug you code.
  234. '           7. Use a label control to display the menu caption as underlined
  235. '           VB-1 NOTE:  VB1 does not return the MenuName or TagText property. Both will be
  236. '                       returned as NULL strings when VB1 is used. The Caption property and
  237. '                       the hMenu/MenuID values can be used to determine VB1 menu items.
  238. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  239. Dim Msg As String
  240. Dim ndex As Integer
  241. Dim lMenuID As Long
  242.     ' clear the junk...
  243.     TXT_Result.Text = ""
  244.     ' for vb2-3 use the following code
  245.     If MenuName = "" And MenuCaption = "" Then
  246.         ' if MenuCaption = ""
  247.         ' then it is a system menu or a separator bar
  248.         ' clear the status text if you want to
  249.         TXT_Result.Text = "Menu Clear"
  250.         ' make the label show the same text
  251.         Label1.Caption = TXT_Result.Text
  252.     ElseIf MenuName = "" Then
  253.         ' detects a system menu item
  254.         TXT_Result.Text = "System Menu = " & MenuCaption
  255.         ' make the label show the same text
  256.         Label1.Caption = TXT_Result.Text
  257.     Else
  258.         ' regular VB menu item
  259.         '
  260.         ' use a label caption to cause the formating
  261.         ' of underline character
  262.         ' the text we want is stored in the
  263.         ' tag property of the menu item
  264.         Label1.Caption = TagText
  265.         ' this is just some data to display in the text box
  266.         TXT_Result.Text = "VB Menu item name = " + MenuName + CRLF + "VB Menu item hMenu = " + Str$(hMenu) + CRLF + "MenuID = " + Str$(MenuID) + CRLF + "Menu Caption = " + MenuCaption
  267.     End If
  268.     Debug.Print "MenuName    = "; MenuName
  269.     Debug.Print "MenuCaption = "; MenuCaption
  270.     Debug.Print "TagText     = "; TagText
  271. Exit Sub
  272.     '
  273.     ' The following illustrates what can be done for VB1 useage.
  274.     '
  275.     '
  276.     ' for simple status text
  277.     ' use a select case statement
  278.     ' match up the MenuCaption returned to the VB Menu Caption property
  279.     '       include the underline character as appropiate
  280.     ' display the text based on the result of the switch statement.
  281.     Select Case MenuCaption
  282.         
  283.         Case "File"
  284.             Label1.Caption = "Open, Close, exit"
  285.         Case "Edit"
  286.             Label1.Caption = "Edit, Cut, Copy, Paste text"
  287.         Case "View"
  288.             Label1.Caption = "View menu choices"
  289.     End Select
  290. End Sub
  291. Sub Clacker1_ClearStatusClick ()
  292. '' PURPOSE: Event returned by CLACKER.VBX
  293. ''COMMENTS: Event is returned when a menu item is
  294. ''          actually selected by the user.
  295. '' USEAGE:  Clear the status line of text if desired
  296. ''''''''''''''''''''''''''''''''''''''''''''''''''''
  297. Dim Msg As String
  298.     Msg = "Illustrates the clear function for the staus text." + CRLF
  299.     Msg = Msg + "You would normally just output a blank line" + CRLF
  300.     Msg = Msg + "when a menu command is actually executed."
  301.     TXT_Result.Text = Msg
  302.     Label1.Caption = ""
  303. End Sub
  304. Sub Clacker1_RefreshHwndClick (MenuItemCount As Integer)
  305. '' PURPOSE: Event returned by CLACKER.VBX
  306. ''COMMENTS: Event is returned in response to the CLACKER.VBX
  307. ''          being issued the command "Clacker1.RefreshHwnd = [HWND]
  308. '' USEAGE:  Load the local array from the CLACKER.VBX control
  309. ''          with the menu IDs of all menu items associated
  310. ''          with the hwnd sent.
  311. ''          This local array is then used for finding the position of the
  312. ''          status text to display.
  313. ''          The MenuID returned in the array is the same as the MenuID parameter
  314. ''          returned in the ClackerClick() event
  315. ''''''''''''''''''''''''''''''''''''''''''''''''''''
  316. Dim ndex As Integer
  317. Dim Msg As String
  318.     '' A return value of 0 indicates the menu was not found
  319.     '' or the hwnd passed was no good
  320.     If (MenuItemCount = 0) Then
  321.         ' just for debugging, don't use in final apps
  322.         MsgBox "MenuItemCount = 0"
  323.         Exit Sub
  324.     Else
  325.         Debug.Print ""
  326.         Debug.Print "MenuItemCount = "; MenuItemCount
  327.         Label1.Caption = "Menu Item Count = " + Str$(MenuItemCount)
  328.     End If
  329.     '' set the array size to MenuItemCount
  330.     ReDim LocalMenuIDArray(1 To MenuItemCount)
  331.     '' fill the array
  332.     For ndex = 1 To MenuItemCount
  333.         '' move the data to the loacal array
  334.         LocalMenuIDArray(ndex) = Clacker1.MenuIDArray(ndex)
  335.         '' for diagnostic use to show what is going on
  336.         '' put up data we stored
  337.         ''Debug.Print "LocalMenuIDArray(" + Str$(ndex) + ") = "; Str$(Clacker1.MenuIDArray(ndex))
  338.     Next ndex
  339. End Sub
  340. Sub Form_Load ()
  341. Dim hSysMenu As Integer
  342. Dim hMainMenu As Integer
  343. Dim Msg As String
  344. Dim ndex As Integer
  345.     '' first load the global constant
  346.     CRLF = Chr$(13) + Chr$(10)
  347.     If Me.WindowState = 0 Then
  348.         Top = 0
  349.         Left = 0
  350.     End If
  351.     '' set the HWND of this form
  352.     Clacker1.hwndForm = Me.hWnd
  353.     '' issue the action command to start sending menu message notifications to your VB app
  354.     Clacker1.Action = CLACKER_START   ''1
  355.     '' If you DO NOT wish to use the array approach to matching MenuID to
  356.     '' the help text, then it is not necessary to use the following lines of code
  357.     '' JUST EXIT HERE
  358.     '' fill the local array
  359.     Clacker1.RefreshHwnd = Me.hWnd
  360.     ''
  361.     '' The array is filled and the event
  362.     '' Clacker1_RefreshHwndClick (MenuItemCount As Integer)
  363.     '' is used to transfer the values into the LocalHwndArray[]
  364.     ''
  365.     ''
  366. End Sub
  367. Sub Form_Resize ()
  368.     If Me.WindowState = 0 Then
  369.         Me.Height = 6270
  370.         Me.Width = 5175
  371.     End If
  372. End Sub
  373. Sub Form_Unload (Cancel As Integer)
  374.     '' good programming practice to clean up
  375.     '' unhook the menu
  376.     Clacker1.Action = CLACKER_STOP  ''2
  377. End Sub
  378. Sub MenuHelpText ()
  379. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  380. '  PURPOSE: Load the help text string in the array.
  381. ' COMMENTS: Make sure you provide an entry for each menu in your
  382. '           menu system, even if it won't be used. This helps when
  383. '           laying out the help system and with debugging.
  384. '    NOTES: 1. To conserve stack space in the main module
  385. '               place the text strings and the array in another module
  386. '           2. The MenuStatus array size must be equal to or great than the total
  387. '               number of menu items in the form, or else a bounds error will occur.
  388. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  389.     MenuStatus(1).strHelpMsg = "<System Menu>"
  390.     MenuStatus(2).strHelpMsg = "Restore previous window position"
  391.     MenuStatus(3).strHelpMsg = "Move the current window Window"
  392.     MenuStatus(4).strHelpMsg = "Change the size of current Window"
  393.     MenuStatus(5).strHelpMsg = "Minimize current Window"
  394.     MenuStatus(6).strHelpMsg = "Maximize current Window"
  395.     MenuStatus(7).strHelpMsg = "[separator]"        '[separator], no MenuID and no text
  396.     MenuStatus(8).strHelpMsg = "Close current Window"
  397.     MenuStatus(9).strHelpMsg = "[separator]"        '[separator], no MenuID and no text
  398.     MenuStatus(10).strHelpMsg = "Switch to different task"
  399.     MenuStatus(11).strHelpMsg = "<Main Form Menu>"
  400.     MenuStatus(12).strHelpMsg = "<File Menu>"
  401.     MenuStatus(13).strHelpMsg = "Exit the program"
  402.     MenuStatus(14).strHelpMsg = "<Edit Menu>"
  403.     MenuStatus(15).strHelpMsg = "Cut selected text from document"
  404.     MenuStatus(16).strHelpMsg = "Copy selected text to clipboard"
  405.     MenuStatus(17).strHelpMsg = "Paste clipboard text into document"
  406.     MenuStatus(18).strHelpMsg = "Main Submenu text"
  407.     MenuStatus(19).strHelpMsg = "Submenu1 text message"
  408.     MenuStatus(20).strHelpMsg = "Submenu2 text message"
  409. End Sub
  410. Sub mnu_Close_Click ()
  411.     '
  412.     ' process should not terminate with menus still hooked in dll
  413.     Clacker1.Action = CLACKER_STOP  ''2
  414.     End
  415. End Sub
  416. Sub mnu_Exit_Click ()
  417.     '
  418.     ' process should not terminate with menus still hooked in dll
  419.     Clacker1.Action = CLACKER_STOP  ''2
  420.     End
  421. End Sub
  422.